<template>
  <div class="register-container">
    <el-page-header @back="goBack" content="租客注册" class="page-header"></el-page-header>
    <el-steps :active="active" finish-status="success" class="steps" align-center>
      <el-step title="注册账号"></el-step>
      <el-step title="资料填写"></el-step>
      <el-step title="注册完成"></el-step>
    </el-steps>
    <router-view></router-view>
    <el-button
      :disabled="!this.$store.state.isRegistered"
      type="primary"
      class="next-button"
      @click="next"
    >下一步</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0
    };
  },
  mounted() {
    const currentRoute = this.$route.path;
    const newRoute = "/account";

    if (currentRoute !== newRoute) {
      this.$router.push(
        newRoute,
        () => {},
        () => {}
      );
    }
  },
  methods: {
    next() {
      this.active++;
      if (this.active == 0) {
        this.$router.push(
          "/account",
          () => {},
          () => {}
        );
      } else if (this.active == 1) {
        this.$router.push(
          "/info",
          () => {},
          () => {}
        );
      } else if (this.active == 2) {
        this.$router.push(
          "/finish",
          () => {},
          () => {}
        );
      } else {
        this.$router.push(
          "/login",
          () => {},
          () => {}
        );
        this.$store.commit("setIsRegistered", false);
        this.$store.commit("setRegisterTenant", null);
      }
    },
    goBack() {
      this.active--;
      if (this.active == -1) {
        this.$router.push(
          "/login",
          () => {},
          () => {}
        );
      } else if (this.active == 0) {
        this.$store.commit("setIsRegistered", false);
        this.$store.commit("setRegisterTenant", null);
        this.$router.push(
          "/account",
          () => {},
          () => {}
        );
      } else if (this.active == 1) {
        this.$router.push(
          "/info",
          () => {},
          () => {}
        );
      }
    }
  }
};
</script>

<style scoped>
.register-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.page-header {
  width: 100%;
  max-width: 1400px;
  margin-bottom: 20px;
}

.steps {
  width: 100%;
  max-width: 1400px;
  margin-bottom: 20px;
}

.next-button {
  margin-top: 12px;
  align-self: center;
}
</style>
